package com.hardroid.workload.workcalc;

import java.io.Serializable;
import java.util.Date;

import com.hardroid.workload.utils.HardroidUtils;

public class Tally implements Serializable {

	public Date obsvTime;
	public boolean productive;
	public boolean nProductive;
	public boolean unknown;
	public String description;

	public Tally() {
		obsvTime = new Date();
		productive = false;
		nProductive = false;
		unknown = true;
		description = "";
	}

	public Tally(Tally tally) {
		obsvTime = new Date(tally.obsvTime.getTime());
		productive = tally.productive;
		nProductive = tally.nProductive;
		unknown = tally.unknown;
		description = new String(tally.description);
	}

	public Tally(Date date) {
		obsvTime = date;
		productive = false;
		nProductive = false;
		unknown = true;
		description = "";		
	}

	public Tally(Date obsvTime, boolean p, boolean np, boolean u, String desc) {
		this.obsvTime = obsvTime;
		this.productive = p;
		this.nProductive = np;
		this.unknown = u;
		this.description = desc;
	}

	/** Mengeset waktu observasi
	 * @param string merupakan string yang telah terformat oleh {@link HardroidUtils#dateToXML(Date)}
	 */
	public void setTime(String string) {
		obsvTime = HardroidUtils.XMLDateToDate(string);
	}
	
	
	/** Mengeset nilai deskripsi
	 * @param desc
	 */
	public void setDescription(String desc){
		this.description = desc;
	}

	/**
	 * Mendapatkan representasi string dari waktu observasi
	 * @return {@link String}
	 */
	public String getXMLSObsvTime(){
		return HardroidUtils.dateToXML(obsvTime);
	}
	
	/** Mendapatkan deskripsi
	 * @return {@link String}
	 */
	public String getDescription(){
		return description;
	}
	
	/** Mendapatkan representasi dari status tally, apakah tally productive, non productive atau unknown
	 * @return {@link String}
	 */
	public String getTallyStatus() {
		if (productive && !nProductive && !unknown) {
			return "p";
		} else if (!productive && nProductive && !unknown) {
			return "np";
		} else if (!productive && !nProductive && unknown) {
			return "u";
		}
		return "unknown";
	}

	/** Mengeset tally agar status tally menjadi seperti status yang diset
	 * @param status
	 */
	public void setTallyStatus(String status) {
		if (status.equals("p")) {
			productive = true;
			nProductive = false;
			unknown = false;
		} else if (status.equals("np")) {
			productive = false;
			nProductive = true;
			unknown = false;
		} else if (status.equals("u")) {
			productive = false;
			nProductive = false;
			unknown = true;
		}

	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return HardroidUtils.dateToTime(obsvTime) + " " + getTallyStatus()
				+ " " + description;
	}

}
